# -*- coding: utf-8 -*-
"""
Created on Mon Mar 02 18:05:28 2015

@author: Maxim

calculation of a flight envelope
1. stall speed
2. absolute ceiling
3. maximum speed
4. minimum speed
"""
from flight_conditions import ISAtmosphere
import numpy as np
import matplotlib.pyplot as plt

def get_flight_envelope(ac,fuelFraction=0.5):
    CLmax = 1.2
    S = 30.0
    W = 3200.0
    alt = np.linspace(0,15000,20)
    
    # --- stall speed limit ---
    Mach = np.zeros(len(alt))
    rho = np.zeros(len(alt))
    for i,h in enumerate(alt):
        atm = ISAtmosphere(h)
        rho = atm.density
        Vstall = (2.*W/(rho*S*CLmax))**0.5
        Mach[i] = Vstall/atm.soundSpeed
    
    # --- absolute ceiling ---
    
    # --- maximum speed at full thrust ---
    
    # --- minimum speed at full thrust ---
    
    plt.figure()
    plt.grid(True)
    plt.plot(Mach,alt,'ro-')
    plt.axis([0,1,0,15e3])
    plt.show()

if __name__=="__main__":
    get_flight_envelope(1,2)